<template>
  <transition name="u-fade">
    <!-- 遮罩层 -->
    <div v-if="modelValue" class="u-mask" @click="closePopup"></div>
  </transition>

  <transition name="u-slide-up">
    <div v-if="modelValue" class="u-popup">
      <div class="popup-content">
        <!-- 插槽内容 -->
        <slot />
      </div>
      <!-- <button class="popup-close" @click="closePopup">关闭</button> -->
    </div>
  </transition>
</template>

<script setup>
defineProps({
  modelValue: { type: Boolean, default: false }
})
const emit = defineEmits(['update:modelValue'])

const closePopup = () => {
  emit('update:modelValue', false)
}
</script>

<style scoped>
/* 遮罩层 */
.u-mask {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 999;
}

/* 弹窗主体 */
.u-popup {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  background: #fff;
  box-shadow: 0 -4px 10px rgba(0, 0, 0, 0.2);
  border-top-left-radius: 12px;
  border-top-right-radius: 12px;
  z-index: 1000;
}

/* 内容区 */
.popup-content {
  padding: 20px;
  min-height: 120px;
}

/* 关闭按钮 */
.popup-close {
  display: block;
  width: 100%;
  padding: 12px;
  border: none;
  background: #f5f5f5;
  font-size: 16px;
}

/* 遮罩淡入淡出 */
.u-fade-enter-active,
.u-fade-leave-active {
  transition: opacity 0.3s;
}
.u-fade-enter-from,
.u-fade-leave-to {
  opacity: 0;
}

/* 弹窗滑入 */
.u-slide-up-enter-active,
.u-slide-up-leave-active {
  transition: all 0.3s ease;
}
.u-slide-up-enter-from,
.u-slide-up-leave-to {
  transform: translateY(100%);
  opacity: 0;
}
.u-slide-up-enter-to,
.u-slide-up-leave-from {
  transform: translateY(0);
  opacity: 1;
}
</style>
